const qiniu = require('qiniu');
const accessKey = 'XSD5WbJMtgf1ctD9FR2kbMfTxYDZWqPnB8sJ_b1h';
const secretKey = 'YLp_qCiaPZq4sYJVeT0-rBN1k2eBvj0HPGN54QmU';
const bucket = 'tinyxu-wx';
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
const config = new qiniu.conf.Config();
//config.useHttpsDomain = true;

config.zone = qiniu.zone.Zone_z2;
const bucketManager = new qiniu.rs.BucketManager(mac, config);

export const removeFile = (key: string) => {
  return new Promise((resolve, reject) => {
    bucketManager.delete(bucket, key, function (err, respBody, respInfo) {
      if (err) {
        reject(err);
      } else {
        resolve({ code: respInfo.statusCode, respBody });
        console.log(`{ code:${respInfo.statusCode},mes:${respBody} }`);
      }
    });
  });
};
